export default {
  namespaced: true,
  state: {
    orderPrescriptionList: '',
    fetchCity: '福州市',
    prescriptionIds: '',
    fetchPatient: '',
    fetchAddress: ''
  },
  getters: {
    orderPrescriptionList: state => {
      if (!state.orderPrescriptionList) {
        try {
          const orderPrescriptionList = localStorage.getItem(
            process.env.VUE_APP_USER_ORDER_PRESCRIPTION_LIST
          )
          state.orderPrescriptionList = orderPrescriptionList
        } catch (e) {
          console.error(e)
        }
      }
      return state.orderPrescriptionList
    },
    fetchCity: state => {
      // VUE_APP_USER_FETCH_CITY
      if (!state.fetchCity) {
        try {
          const orderPrescriptionList = localStorage.getItem(
            process.env.VUE_APP_USER_FETCH_CITY
          )
          state.fetchCity = orderPrescriptionList
        } catch (e) {
          console.error(e)
        }
      }
      return state.fetchCity
    },
    prescriptionIds: state => {
      if (!state.prescriptionIds) {
        try {
          const prescriptionIds = localStorage.getItem(
            process.env.VUE_APP_USER_PRESCRIPTION_IDS
          )
          state.prescriptionIds = prescriptionIds
        } catch (e) {
          console.error(e)
        }
      }
      return state.prescriptionIds
    },
    fetchPatient: state => {
      if (!state.fetchPatient) {
        try {
          const fetchPatient = localStorage.getItem(
            process.env.VUE_APP_USER_FETCH_PATIENT
          )
          state.fetchPatient = fetchPatient
        } catch (e) {
          console.error(e)
        }
      }
      return state.fetchPatient
    },
    fetchAddress: state => {
      if (!state.fetchAddress) {
        try {
          const fetchAddress = localStorage.getItem(
            process.env.VUE_APP_USER_FETCH_ADDRESS
          )
          state.address = fetchAddress
        } catch (e) {
          console.error(e)
        }
      }
      return state.fetchAddress
    }
  },
  mutations: {
    setOrderPrescriptionList (state, orderPrescriptionList) {
      // console.log(token);
      state.orderPrescriptionList = orderPrescriptionList
      localStorage.setItem(
        process.env.VUE_APP_USER_ORDER_PRESCRIPTION_LIST,
        orderPrescriptionList
      )
    },
    setFetchCity (state, fetchCity) {
      console.log(fetchCity)
      state.fetchCity = fetchCity
      localStorage.setItem(process.env.VUE_APP_USER_FETCH_CITY, fetchCity)
    },
    setPrescriptionIds (state, prescriptionIds) {
      state.prescriptionIds = prescriptionIds
      // VUE_APP_USER_PRESCRIPTION_Ids
      localStorage.setItem(
        process.env.VUE_APP_USER_PRESCRIPTION_IDS,
        prescriptionIds
      )
    },
    setFetchPatient (state, fetchPatient) {
      state.fetchPatient = fetchPatient
      // VUE_APP_USER_PRESCRIPTION_Ids
      localStorage.setItem(
        process.env.VUE_APP_USER_FETCH_PATIENT,
        fetchPatient
      )
    },
    setFetchAddress (state, fetchAddress) {
      state.fetchAddress = fetchAddress
      // VUE_APP_USER_PRESCRIPTION_Ids
      localStorage.setItem(
        process.env.VUE_APP_USER_FETCH_ADDRESS,
        fetchAddress
      )
    }
  }
}
